import java.io.BufferedReader;
import java.io.InputStreamReader;


public class Main {
	
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str1 = br.readLine().trim();
		String str2 = br.readLine().trim();
		int k = Integer.parseInt(br.readLine().trim());
		
		int[][] mem = new int[str1.length() + 1][str2.length() + 1];
		for(int i = 1; i <= str1.length(); i++) {
			mem[i][0] = mem[i - 1][0] + k; 
		}
		
		for(int j = 1; j <= str2.length(); j++) {
			mem[0][j] = mem[0][j - 1] + k;
		}
		
		for(int i = 1; i <= str1.length(); i++) {
			for(int j = 1; j <= str2.length(); j++) {
				mem[i][j] = min(mem[i][j - 1] + k, mem[i - 1][j] + k, mem[i - 1][j - 1] + Math.abs((int)(str1.charAt(i - 1) - str2.charAt(j - 1))));
			}
		}
		
		System.out.println(mem[str1.length()][str2.length()]);
		
	}
	
	private static int min(int a, int b, int c) {
		int max = Math.min(a, b);
		return Math.min(max, c);
	}

}
